<?php

    /**
     * @author AbordageSol
     * @version 1.0
     * @created 04-Mar-2012 1:23:20 PM
     */
    class Invoice {

        var $_ci;

        function Invoice ()
        {
            $this->_ci = & get_instance ();
        }

        /**
         * 
         * @param booking_id
         */
        function ShowInvoice_car1 ( $booking_id )
        {
            if ( !isset ( $booking_id ) )
            {
                echo 'Error ocured.<br /> booking_id is not set.';
                exit ();
            }

            $query = '
            SELECT cb.*, cust.firstName, cust.email , cust.phone, cust.address1, cust.town_city, cust.zip_code, cust.country, car.name as carname, car.description as cardescription
            FROM carbooking as cb
            LEFT JOIN customers as cust ON cb.customerid  = cust.id
            LEFT JOIN car ON cb.carid  = car.id
            WHERE cb.id = ' . $booking_id . '
            ';

            $res = $this->_ci->db->query ( $query );

            return $res;
        }

        /**
         * 
         * @param booking_id
         */
        function ShowInvoice_car2 ( $booking_id )
        {
            if ( !isset ( $booking_id ) )
            {
                echo 'Error ocured.<br /> booking_id is not set.';
                exit ();
            }


            $query = '
            SELECT cbac.*, acd.type, acd.description , acd.price
            FROM cbaccessories as cbac
            LEFT JOIN accessorydescription as acd ON cbac.adId  = acd.id
            WHERE cbac.carBookingId = ' . $booking_id . '
            ';

            $res = $this->_ci->db->query ( $query );

            return $res;
        }

        function ShowInvoice_exc ( $booking_id )
        {
            if ( !isset ( $booking_id ) )
            {
                echo 'Error ocured.<br /> booking_id is not set.';
                exit ();
            }


            $this->data['invoice_no'] = $booking_id;

            //podaci o bookingu
            $query = $this->_ci->db->get_where ( 'excursionbooking', array ('id' => $this->data['invoice_no']) )->result_array ();
            foreach ( $query as $key => $list )
            {
                $this->data['eb_excid'] = $list['excursions_id'];
                $this->data['eb_customerid'] = $list['customers_id'];
                $this->data['eb_date_from'] = date ( 'd.m.Y', $list['date_from'] );
                $this->data['eb_num_of_day'] = $list['num_of_day'];
                $this->data['eb_adultprice'] = $list['adultprice'];
                $this->data['eb_chprice'] = $list['chprice'];
                $this->data['eb_totalprice'] = $list['totalprice'];
                $this->data['eb_noperson'] = $list['noperson'];
                $this->data['eb_noadult'] = $list['noadult'];
                $this->data['eb_noch'] = $list['noch'];
                $this->data['eb_userid'] = $list['userid'];
                $this->data['eb_pickup_location'] = $list['pickup_location'];
            }


            //podaci o customeru
            $query = $this->_ci->db->get_where ( 'customers', array ('id' => $this->data['eb_customerid']) )->result_array ();
            foreach ( $query as $key => $list )
            {
                $this->data['cust_firstName'] = $list['firstName'];
                $this->data['cust_lastName'] = $list['lastName'];
                $this->data['cust_email'] = $list['email'];
                $this->data['cust_phone'] = $list['phone'];
                $this->data['cust_address'] = $list['address1'];
                $this->data['cust_city'] = $list['town_city'];
                $this->data['cust_zip'] = $list['zip_code'];
                $this->data['cust_country'] = $list['country'];
            }


            //podaci o eskurziji
            $query = $this->_ci->db->get_where ( 'excursions', array ('id' => $this->data['eb_excid']) )->result_array ();
            foreach ( $query as $key => $list )
            {
                $this->data['exc_title'] = $list['title'];
                $this->data['exc_startWeekDay'] = $list['startWeekDay'];
                $this->data['exc_addition'] = $list['addition'];
                $this->data['exc_adultPrice'] = $list['adultPrice'];
                $this->data['exc_childPrice'] = $list['childPrice'];
                $this->data['exc_transportsid'] = $list['transportsid'];
                $this->data['exc_guides'] = $list['guides'];
            }


            //podaci o transportu
            $query = $this->_ci->db->get_where ( 'transports', array ('id' => $this->data['exc_transportsid']) )->result_array ();
            foreach ( $query as $key => $list )
            {
                $this->data['tra_title'] = $list['title'];
            }

            // Prepare datas to be handled by View file
            $this->data['invoice_title'] = $this->data['exc_title'];

            $this->data['titles'][0] = 'Start date:';
            $this->data['titles'][1] = 'Transport type:';
            $this->data['titles'][2] = 'Pickup location:';
            $this->data['titles'][3] = 'Add on during journey:';
            $this->data['titles'][4] = 'Guides:';


            $this->data['datas'][0] = date ( 'l', strtotime ( $this->data['eb_date_from'] ) ) . ', ' . $this->data['eb_date_from'];
            $this->data['datas'][1] = $this->data['tra_title'];
            $this->data['datas'][2] = $this->data['eb_pickup_location'] . 'h';
            $this->data['datas'][3] = $this->data['exc_addition'];
            $this->data['datas'][4] = $this->data['exc_guides'];


            //$this->data['price_title'] = 'Price per person:';
            //$this->data['price_desc'] = '&nbsp;';
            //$this->data['price_day_price'] = $this->data['eb_adultprice'];
            //$this->data['price_total_price'] = $this->data['eb_totalprice'];

            $this->data['total_price'] = $this->data['eb_totalprice'];

            return $this->data;
        }

        function ShowInvoice_tour ( $booking_id )
        {
            if ( !isset ( $booking_id ) )
            {
                echo 'Error ocured.<br /> booking_id is not set.';
                exit ();
            }

            $this->data['invoice_no'] = $booking_id;

            //podaci o bookingu
            $query = $this->_ci->db->get_where ( 'tourbooking', array ('id' => $this->data['invoice_no']) )->result_array ();
            foreach ( $query as $key => $list )
            {
                $this->data['tb_id'] = $list['tours_id'];
                $this->data['tb_customerid'] = $list['customers_id'];
                $this->data['tb_date_from'] = date ( 'd.m.Y', $list['date_from'] );
                $this->data['tb_num_of_day'] = $list['num_of_day'];
                $this->data['tb_adultprice'] = $list['adultprice'];
                $this->data['tb_totalprice'] = $list['totalprice'];
                $this->data['tb_noperson'] = $list['noperson'];
                $this->data['tb_userid'] = $list['userid'];
            }


            //podaci o customeru
            $query = $this->_ci->db->get_where ( 'customers', array ('id' => $this->data['tb_customerid']) )->result_array ();
            foreach ( $query as $key => $list )
            {
                $this->data['cust_firstName'] = $list['firstName'];
                $this->data['cust_lastName'] = $list['lastName'];
                $this->data['cust_email'] = $list['email'];
                $this->data['cust_phone'] = $list['phone'];
            }


            //podaci o turi
            $query = $this->_ci->db->get_where ( 'tours', array ('id' => $this->data['tb_id']) )->result_array ();
            foreach ( $query as $key => $list )
            {
                $this->data['t_title'] = $list['title'];
                $this->data['t_addition'] = $list['addition'];
                $this->data['t_nodays'] = $list['nodays'];
                $this->data['t_nonights'] = $list['nonights'];
            }

            // Prepare datas to be handled by View file
            $this->data['invoice_title'] = $this->data['t_title'];

            $this->data['titles'][0] = 'Start date:';
            $this->data['titles'][1] = 'Duration:';
            $this->data['titles'][2] = 'Num. of person/s:';

            $this->data['datas'][0] = $this->data['tb_date_from'];
            $this->data['datas'][1] = $this->data['t_nodays'] . ' days / ' . $this->data['t_nonights'] . ' nights';
            $this->data['datas'][2] = $this->data['tb_noperson'];

            $this->data['price_title'] = 'Price per person:';
            $this->data['price_desc'] = '&nbsp;';
            $this->data['price_day_price'] = $this->data['tb_adultprice'];
            $this->data['price_total_price'] = $this->data['tb_totalprice'];

            $this->data['total_price'] = $this->data['tb_totalprice'];


            return $this->data;
        }

    }

?>
